package ru.inse.realty.web.module;

import java.util.Map;

import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;

import ru.inse.realty.core.service.IRealtyItemService;
import ru.inse.realty.core.service.IRealtyObjectService;
import ru.inse.realty.web.page.RealtyComponentFactory;
import ru.inse.realty.web.page.RealtyPageFactory;
import ru.inse.web.module.IInseModuleRegisterService;
import ru.inse.web.module.InseModule;
import ru.xeden.web.html.module.AbstractModule;

public class RealtyModule
    extends AbstractModule
    implements MessageSourceAware
{
    
    private MessageSource messageSource;
    
    public static final String ID = "realty";
    
    private InseModule inseModule;
    private IRealtyObjectService realtyObjectService;
    private IRealtyItemService realtyItemService;
    
    public RealtyModule()
    {
        setPageFactory(new RealtyPageFactory());
        setComponentFactory(new RealtyComponentFactory(this));
    }

    
    public void setMessageSource(MessageSource messageSource)
    {
        this.messageSource = messageSource;
        System.out.println(messageSource);
    }
    
    public MessageSource getMessageSource()
    {
        return messageSource;
    }

    
    @Override
    public String getDisplayName()
    {
        return "Недвижимость";
    }

    @Override
    public String getUrlPiece()
    {
        return "realty";
    }

    @Override
    public String getId()
    {
        return ID;
    }

    
    @Override
    public int getDisplayOrder()
    {
        return 0;
    }

    // InseModuleRegisterService -----------------------------------------------------
    
    public void inseModuleRegisterServiceBind(IInseModuleRegisterService registerService, Map properties)
    {
        registerService.register(this);
        this.inseModule = registerService.getInseModule();
    }
    
    public void inseModuleRegisterServiceUnbind(IInseModuleRegisterService registerService, Map properties)
    {
        registerService.unregister(this);
        this.inseModule = null;
    }

    public InseModule getInseModule()
    {
        return inseModule;
    }

    // RealtyObjectService ----------------------------------------------------------
    
    public void realtyObjectServiceBind(IRealtyObjectService realtyObjectService, Map properties)
    {
        this.realtyObjectService = realtyObjectService;
    }
    
    public void realtyObjectServiceUnbind(IRealtyObjectService realtyObjectService, Map properties)
    {
        this.realtyObjectService = null;
    }
    
    public IRealtyObjectService getRealtyObjectService()
    {
        return realtyObjectService;
    }

    // RealtyItemService----------------------------------------------------------------
    
    public void realtyItemServiceBind(IRealtyItemService realtyItemService, Map properties)
    {
        this.realtyItemService = realtyItemService;
    }

    public void realtyItemServiceUnbind(IRealtyItemService realtyItemService, Map properties)
    {
        this.realtyItemService = null;
    }
    
    public IRealtyItemService getRealtyItemService()
    {
        return realtyItemService;
    }
}
